package com.ujs.service.impl;

import com.ujs.dao.OrderDao;
import com.ujs.pojo.Order;
import com.ujs.pojo.Product;
import com.ujs.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @title: OrderServiceImpl
 * @Author liyunxiao
 * @Date: 2021/1/10 20:02
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Override
    public List<Order> findAll() {
        return orderDao.findAll();
    }

    @Override
    public Order findById(String id) {
        return orderDao.getOne(id);
    }
    @Override
    public void save(Order order){
        orderDao.save(order);
    }
    @Override
    @Transactional
    public void deleteById(String id){
        Order one = orderDao.getOne(id);
//        orderDao.deleteById(id);
        orderDao.delete(one);
    }

    @Override
    public List<Order> findByPage(Integer page, Integer size) {
            //Sort sort = new Sort(Sort.Direction.DESC, "custId");
            Pageable pageable= PageRequest.of(page,size);

            List<Order> list = orderDao.findAll((root, query, cb) -> {
                return null;
            }, pageable).getContent();

            return list;
    }

    @Override
    public Long findCount() {
        return orderDao.count();
    }

    @Override
    public List<Order> findByOrderNumLike( String num) {
        return orderDao.findByOrderNumLike("%"+num+"%");
    }

}
